package Order.DAO;

import Order.Entity.Order;
import javax.persistence.EntityManager;
import javax.persistence.Query;

public class OrderDAO implements IRepository<Order> {

    public OrderDAO(EntityManager em) {
        this.em = em;
    }

    public Order merge(Order order) {
        return em.merge(order);
    }

    public Order persist(Order order) {
        em.persist(order);
        return order;
    }

    public void remove(Order order) {
        order = em.merge(order);
        em.remove(order);
    }

    public Order FindById(Integer id) {
        Query query = em.createQuery("select m from Order m where m.id = " + id);
        return (Order) query.getSingleResult();
    }
    private EntityManager em;
}
